package com.financing.platform.web.api;

import java.util.Collections;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.financing.platform.common.Pager;
import com.financing.platform.common.ResultCode;
import com.financing.platform.common.ResultMap;
import com.financing.platform.common.ResultMap.STATUS;
import com.financing.platform.service.IBankCardService;
import com.financing.platform.util.Dict;
import com.financing.platform.vo.BankCardVO;

/**
 * 
 * @ClassName: BankCardAction
 * @Description: 银行卡Action 
 * @author  lisu
 *
 */
@Controller("bankCardActionApi")
@RequestMapping("/api/bank")
@Scope("prototype")
public class BankCardAction extends BaseAction{
	
	@Autowired
	private IBankCardService bankCardServiceImpl;
	
	/**
	 * 
	 * @Title: queryBankCard
	 * @Description: 银行卡统计 
	 * @param @param request
	 * @param @param response
	 * @param @param BankCardVO
	 * @param @return   
	 * @return ModelAndView   
	 * @throws
	 */
	@RequestMapping("/queryBankCard.shtml")
	@ResponseBody
	public ResultMap queryBankCard(HttpServletRequest request,
			HttpServletResponse response,BankCardVO cardVO,Pager pager) {
		
		try{
			this.log.info("begin queryBankCard info!");
			
			cardVO.setBegin(pager.getStartIndex());
			cardVO.setPageSize(pager.getPageSize());
			cardVO.setEnd(pager.getPageSize());
			
			int count = bankCardServiceImpl.queryBankCardListCount(cardVO);
			pager.setTotalCount(count);
			
			// request.getSession().setAttribute(Dict.requestID, "queryBankCard.shtml");
			
			List<BankCardVO> bankCardVOs = null;
			
			if(count > 0){
				bankCardVOs = bankCardServiceImpl.queryBankCardList(cardVO);
			}else{
				bankCardVOs = Collections.EMPTY_LIST;
			}
			
			resultMap.setAttribute("list", bankCardVOs);
			resultMap.setAttribute("bean",cardVO);
			resultMap.setAttribute("pager",pager);
			resultMap.setStatus(STATUS.SUCCESS);
			resultMap.setStatusCode(ResultCode.RESULT_CODE_SUCCESS);
			this.log.info("end queryBankCard info access !");
		}catch(Exception e){
			this.log.error("error queryBankCard",e);
			resultMap.setStatus(STATUS.FAILE);
			resultMap.setStatusCode(ResultCode.RESULT_CODE_SYSTEM_ERROR);
		}
		
		return resultMap;
	}
	
}
